require(['grid', 'topBar', 'layout', 'date'], function () {
    $('#top').topBar({
        left: [
            {
                type: 'filter',
                search: function () {
                    search();
                },
                item: [
                    {
                        text: '线路类型',
                        name: 'lineTy',
                        type: 'item-select',
                        data: [
                            {text: '全部', value: ''},
                            {text: '上行', value: '0'},
                            {text: '下行', value: '1'}
                        ]
                    }, {
                        text: '区域类型',
                        // dict: 'LIAREA00',
                        name: 'areaType',
                        type: 'item-select',
                        data: [
                            // {text: '全部', value: ''},
                            {text: '黑点区域', value: 'B'},
                            {text: '站点区域', value: 'S'},
                            {text: '站点间区域', value: 'BS'}
                            // {text: '非运营', value: 'OL'}
                        ]
                    }, {
                        text: '不良行为',
                        url: "/lineDrvStandard/getBadBhvList.htm",
                        name: 'badBhvId',
                        type: 'item-select',
                        key: 'badBhvId',
                        value: 'badBhvName',
                        data: [
                            {text: '全部', value: ''}
                        ]
                    }
                ]
            }
        ],
        right: [
            {
                text: '导出',
                type: 'export-btn',
                authority: '',
                item: [
                    {
                        text: 'Excel导出',
                        click: function () {
                            exportFile('excel');
                        }
                    },
                    {
                        text: 'PDF导出',
                        click: function () {
                            exportFile('pdf');
                        }
                    }
                ]
            }
        ]
    });

    $('body').layout();

    $('#grid').grid({
        url: "/lineDrvStandard/getLineDrvStandardPage.htm",
        height: "410",
        multiselect: false,
        colModel: [
            {name: "lineId", label: "lineId", hidden: true},
            {
                name: "lineName", label: "营运线路", width: 100,
                formatter: 'customCurrency',
                formatoptions: {
                    redbtn: true,
                    css: 'text-link c-blue',
                    clickFn: function (rowObject, cellvalue) {
                        goLineInfo(rowObject.lineId);
                    }
                }
            },
            {name: "lineTy", label: "方向", width: 80},
            {name: "areaType", label: "区域类型", width: 80},
            {name: "areaName", label: "区域名称", width: 140},
            {name: "badBhvName", label: "不良行为", width: 140},
            {name: "meanVal", label: "平均值", width: 80},
            {name: "threVal", label: "异常阀值", width: 80},
            {name: "threLasTim", label: "持续时长阀值", width: 80}
        ]
    });

    function search() {
        var $postData = $("#top").parent().getValues();
        // 左侧树tab选中的类型
        var type = commonFun.getLeftTreeCurrentTreeType();
        var orgIds = commonFun.getLeftTreeCheckedNodes(type);
        if (type != 'LINE' || !orgIds) {
            $.messager.alert("提示", "请切换到线路树，选择查询线路！", "info");
        } else {
            $postData.type = type;
            $postData.orgIds = orgIds.toString();

            console.log($postData);

            $('#grid').grid('setGridParam', {
                datatype: "json",
                postData: $postData
            }).trigger("reloadGrid");
        }
    }

    function exportFile(fileTy) {
        if ($('#grid').getGridParam("reccount") > 0) {
            var url = "/lineDrvStandard/exportLineDrvStandard.htm";
            var type = commonFun.getLeftTreeCurrentTreeType();
            var orgIds = commonFun.getLeftTreeCheckedNodes(type);
            if (type != 'LINE' || !orgIds) {
                $.messager.alert("提示", "请切换到线路树，选择查询线路！", "info");
            } else {
                var $postData = $("#top").parent().getValues();
                $postData.fileTy = fileTy;
                $postData.type = type;
                $postData.orgIds = orgIds;
                $.exportFile(url, $postData);
            }
        } else {
            $.messager.alert("提示", "请先查询数据！", "info");
        }
    }


});